// AWTEventMulticaster.cpp: implementation of the AWTEventMulticaster class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "AWTTest.h"
#include "AWTEventMulticaster.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(AWTEventMulticaster, AWTObject)

AWTEventMulticaster::AWTEventMulticaster(AWTEventListener* a, AWTEventListener* b)
{
	m_a = a; 
	m_b = b;
}
AWTEventMulticaster::~AWTEventMulticaster()
{
	if (m_a->isMultiCaster())
	{
#ifdef UNDER_CE
//		AWTEventMulticaster* mc = (AWTEventMulticaster*)m_a;
	delete m_a;
#else
		AWTEventMulticaster* mc = dynamic_cast<AWTEventMulticaster*>(m_a);
		delete mc;
#endif		
	}
	if (m_b->isMultiCaster())
	{
#ifdef UNDER_CE
//		AWTEventMulticaster* mc = (AWTEventMulticaster*)m_b;
	delete m_b;
#else
		AWTEventMulticaster* mc = dynamic_cast<AWTEventMulticaster*>(m_b);
		delete mc;
#endif		
	}
}

AWTEventListener* AWTEventMulticaster::remove(AWTEventListener* oldl)
{
	if (oldl == m_a)  return m_b;
	if (oldl == m_b)  return m_a;
	AWTEventListener* a2 = removeInternal(m_a, oldl);
	AWTEventListener* b2 = removeInternal(m_b, oldl);
	if (a2 == m_a && b2 == m_b) 
	{
	  return (reinterpret_cast<AWTEventListener*>(this));	// it's not here
	}
//	return addInternal(a2, b2);
	return NULL;
}

AWTComponentListener* AWTEventMulticaster::add(AWTComponentListener* a, AWTComponentListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTComponentListener*)m;
#else
	return dynamic_cast<AWTComponentListener*>(m);
#endif
}

AWTActionListener* AWTEventMulticaster::add(AWTActionListener* a, AWTActionListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTActionListener*)m;
#else
	return dynamic_cast<AWTActionListener*>(m);
#endif
}

AWTFocusListener* AWTEventMulticaster::add(AWTFocusListener* a, AWTFocusListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTFocusListener*)m;
#else
	return dynamic_cast<AWTFocusListener*>(m);
#endif
}

AWTKeyListener* AWTEventMulticaster::add(AWTKeyListener* a, AWTKeyListener* b)
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTKeyListener*)m;
#else
	return dynamic_cast<AWTKeyListener*>(m);
#endif
}

AWTItemListener* AWTEventMulticaster::add(AWTItemListener* a, AWTItemListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTItemListener*)m;
#else
	return dynamic_cast<AWTItemListener*>(m);
#endif
}

AWTMouseListener* AWTEventMulticaster::add(AWTMouseListener* a, AWTMouseListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTMouseListener*)m;
#else
	return dynamic_cast<AWTMouseListener*>(m);
#endif
}

AWTMouseMotionListener* AWTEventMulticaster::add(AWTMouseMotionListener* a, AWTMouseMotionListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTMouseMotionListener*)m;
#else
	return dynamic_cast<AWTMouseMotionListener*>(m);
#endif
}

AWTWindowListener* AWTEventMulticaster::add(AWTWindowListener* a, AWTWindowListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTWindowListener*)m;
#else
	return dynamic_cast<AWTWindowListener*>(m);
#endif
}

AWTAdjustmentListener* AWTEventMulticaster::add(AWTAdjustmentListener* a, AWTAdjustmentListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTAdjustmentListener*)m;
#else
	return dynamic_cast<AWTAdjustmentListener*>(m);
#endif
}

AWTTextListener* AWTEventMulticaster::add(AWTTextListener* a, AWTTextListener* b) 
{
	if (a == NULL)  return b;
	if (b == NULL)  return a;
	AWTEventMulticaster* m = new AWTEventMulticaster(a, b);
#ifdef UNDER_CE
	return (AWTTextListener*)m;
#else
	return dynamic_cast<AWTTextListener*>(m);
#endif
}






